package com.alogic.xscript.cert;

import com.alogic.xscript.AbstractLogiclet;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
import java.security.cert.X509Certificate;

/**
 * 证书查询
 */
public abstract class CertQuery extends AbstractLogiclet{
    protected String pid = "$certificate";

    public CertQuery(String tag, Logiclet p) {
        super(tag, p);
    }

    @Override
    public void configure(Properties p){
        super.configure(p);
        pid = PropertiesConstants.getString(p,"pid",pid,true);
    }

    @Override
    protected void onExecute(XsObject root, XsObject current, final LogicletContext ctx, final ExecuteWatcher watcher){
        X509Certificate content = ctx.getObject(pid);
        if (content != null){
            onExecute(content,root,current,ctx,watcher);
        }else{
            log(String.format("X509Certificate object is null,pid=%s",pid),"warnning");
        }
    }

    protected abstract void onExecute(X509Certificate content, XsObject root, XsObject current, LogicletContext ctx, ExecuteWatcher watcher);
}
